home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #45 (Jun 89) / Supe SubCode / TrapDefs.a < prev    next >
Text File  |  1988-10-12  |  5KB  |  147 lines

  1.                 PRINT            OFF
  2.                 INCLUDE        'Traps.a'
  3.                 INCLUDE        'SysEqu.a'
  4.                 PRINT            ON,OBJ
  5.                 
  6.                 CODEREFS        FORCEJT
  7.  
  8. StackFrame    RECORD            {A6Link},DECR
  9.                     DataSizePtr:ds.l    1
  10.                     TrapSizePtr:ds.l    1
  11.                     TrapAddrPtr:ds.l    1
  12.                     retaddr:        ds.l    1
  13.                     A6Link:        ds.l    1
  14.                     stacksize:    EQU    *
  15.                 ENDR
  16.                 
  17. ; =============================================================================
  18.  
  19. GetDrawTrapInfo PROC     EXPORT
  20.  
  21.                     WITH StackFrame
  22.                         link        a6,#stacksize
  23.                         move.l    DataSizePtr(a6),a0
  24.                         lea        ParmEnd-ParmBeg,a1        ; compute size of parm's.
  25.                         move.l    a1,(a0)                        ; put it in a 'c' variable.
  26.                         move.l    TrapSizePtr(a6),a0
  27.                         lea        TrapEnd-TrapBeg,a1        ; compute size of trap code.
  28.                         move.l    a1,(a0)                        ; put it in a 'c' variable.
  29.                         move.l    TrapAddrPtr(a6),a0
  30.                         lea        TrapBeg,a1                    ; put hook address ...
  31.                         move.l    a1,(a0)                        ; in a 'c' variable.
  32.                         unlk        a6
  33.                         rts
  34.                     ENDWITH
  35.  
  36. ParmBeg
  37. SvRTS                dc.l    0                ; place holder for compiling.
  38. FcAdr                dc.l    0                ; place holder for compiling.
  39. TpAdr                dc.l    0                ; place holder for compiling.
  40. CLvl                dc.l    0                ; place holder for compiling.
  41. ParmEnd
  42.  
  43.                 ; The following block of code actually gets copied down into 
  44.                 ; the SysHeap due to trap table nearness requirements...
  45.             
  46. TrapBeg            lea        CLvl,a0
  47.                     addq.w    #1,(a0)            ; keep track of nested hook calls.
  48.                     cmpi.w    #1,(a0)            ; see how many calls deep we are.
  49.                     bgt.s        CallTrap            ; just call trap if call level > 1.
  50.                             
  51. CallHook            lea        SvRTS,a0            ; save address to get back too...
  52.                     move.l    (a7)+,(a0)
  53.                     move.w    (a7),d0            ; save 'len' pascal parm to 'DrawText'
  54.                     clr.w        (a7)                ; 'clr.w' transforms 'offset' parm to MPW-C 'int'
  55.                     ext.l        d0                    ; now transform 'len' parm to MPW-C 'int'.
  56.                     move.l    d0,-(a7)            ; put 'len' parm back on stack.
  57.                     move.l    FcAdr,a0            ; get out address of our trap.
  58.                     jsr        (a0)                ; call it with MPW-C stack parms. 
  59.                     add.l        #12,a7            ; do a 'pascal' clean up.
  60.                     lea        CLvl,a0
  61.                     subi.w    #1,(a0)            ; indicate exit of nested call.
  62.                     move.l    SvRTS,a0            ; setup jump to original caller.
  63.                     jmp        (a0)                ; get out of here!!
  64.                             
  65. CallTrap            lea        CLvl,a0
  66.                     subi.w    #1,(a0)            ; indicate exit of nested call.
  67.                     move.l    TpAdr,a0            ; just call standard trap.
  68.                     jmp        (a0)                ; this won't come back here.
  69. TrapEnd
  70.  
  71.                 ENDPROC
  72.                 
  73. ; =============================================================================
  74.  
  75. GetResTrapInfo PROC    EXPORT
  76.  
  77.                     WITH StackFrame
  78.                         link        a6,#stacksize
  79.                         move.l    DataSizePtr(a6),a0
  80.                         lea        ParmEnd-ParmBeg,a1        ; compute size of parm's.
  81.                         move.l    a1,(a0)                        ; put it in a 'c' variable.
  82.                         move.l    TrapSizePtr(a6),a0
  83.                         lea        TrapEnd-TrapBeg,a1        ; compute size of trap code.
  84.                         move.l    a1,(a0)                        ; put it in a 'c' variable.
  85.                         move.l    TrapAddrPtr(a6),a0
  86.                         lea        TrapBeg,a1                    ; put hook address ...
  87.                         move.l    a1,(a0)                        ; in a 'c' variable.
  88.                         unlk        a6
  89.                         rts
  90.                     ENDWITH
  91.                         
  92. ParmBeg
  93. SvRTS                dc.l    0                ; place holder for compiling.
  94. FcAdr                dc.l    0                ; place holder for compiling.
  95. TpAdr                dc.l    0                ; place holder for compiling.
  96. CLvl                dc.l    0                ; place holder for compiling.
  97. ParmEnd
  98.  
  99. FontID            EQU    4
  100.  
  101.                     ; The following block of code actually gets copied down into 
  102.                     ; the SysHeap due to trap table nearness requirements...
  103.  
  104. TrapBeg            lea        CLvl,a0
  105.                     addi.w    #1,(a0)            ; keep track of nested hook calls.
  106.                     cmpi.w    #1,(a0)            ; see how many calls deep we are.
  107.                     bgt.s        CallTrap            ; just call trap if call level > 1.
  108.                         
  109. CallHook:        move.l    6(a7),d0            ; unload the resType from the stack.
  110.                     cmpi.l    #'FOND',d0        ; check it for type 'FOND'.
  111.                     bne.s        CallTrap            ; do nothing if it isn't.
  112.                     andi.w    #$1FFF,FontID(a7) ; else - clear the special super/sub bits
  113.                                                         ; so FontMgr gets Font info of a known Font.
  114.  
  115. CallTrap:        lea        CLvl,a0
  116.                     subi.w    #1,(a0)            ; indicate exit of nested call.
  117.                     move.l    TpAdr,a0            ; just call standard trap.
  118.                     jmp        (a0)                ; this won't come back here.
  119. TrapEnd
  120.                 ENDPROC
  121.                 
  122. ; =============================================================================
  123.  
  124. UnChainHook    PROC    EXPORT
  125.                     WITH StackFrame
  126.                         link        a6,#stacksize
  127.                         move.l    TrapSizePtr(a6),a0
  128.                         lea        TrapEnd-NormTrap,a1        ; compute size of trap code.
  129.                         move.l    a1,(a0)                        ; put it in a 'c' variable.
  130.                         move.l    TrapAddrPtr(a6),a0
  131.                         lea        NormTrap,a1                    ; put hook address ...
  132.                         move.l    a1,(a0)                        ; put it in a 'c' variable.
  133.                         unlk        a6
  134.                         rts
  135.                     ENDWITH
  136.  
  137.  
  138. SvRTS                dc.l    0                ; place holder for compiling.
  139. FcAdr                dc.l    0                ; place holder for compiling.
  140. TpAdr                dc.l    0                ; place holder for compiling.
  141. CLvl                dc.l    0                ; place holder for compiling.
  142.  
  143. NormTrap            move.l    TpAdr,a0        ; just call standard trap.
  144.                     jmp        (a0)            ; this won't come back here.
  145. TrapEnd    
  146.                 ENDPROC
  147.             END